﻿
var serializer = new JSONSerializer();

$(document).ready(function () {

    var url = new Url();
    var $Id = url.GetQueryString("orderId");


    //绑定详情
    $.ajax({
        type: "post",
        url: "../Handler/FinancialOrder.ashx",
        dataType: "json",
        data: { Id: $Id, type: 4, _: Math.random() },
        async: false,
        cache: false,
        complete: function () {
        },
        success: function (data) {
            if (data.Status) {
                if (data.Data.Order) {
                    $(':hidden[name=FinaOrderId]').val(data.Data.Order.OrderId);
                    $(".divAmount").text(data.Data.Order.Amount * 10000);
                    $(".divIncome").text(data.Data.Order.Income);//收益
                    $(".divTerm").text(data.Data.Order.Term);
                    $(".divFee").text(data.Data.Order.Fee);
                    $(".divInitialLoanDate").text(data.Data.Order.InitialLoanDate);//初始出借日期
                    $(".divMemo").text(data.Data.Order.Memo);
                    $(".divPayBank").text(data.Data.Order.PayBankName);
                    $(".divDepositBank").text(data.Data.Order.DepositBank);
                    $(".divRecAccName").text(data.Data.Order.RecAccName);
                    $(".divRecAccNum").text(data.Data.Order.RecAccNum);
                    $(".divAgreeNum").text(data.Data.Order.AgreeNum);
                    $(".divFinaNum").text(data.Data.Order.OrderId);
                    $(".divProductType").text(data.Data.Order.Product);
                }
                if (data.Data.User) {
                    $(".divUserId").text(data.Data.User.Name);
                }

                //预加载债权匹配信息列表
                $.ajax({
                    type: "post",
                    url: "../Handler/CreditMatchHandler.ashx",
                    dataType: "json",
                    data: { FinaOrderId: $Id, type: 0, _: Math.random() },
                    async: true,
                    cache: false,
                    complete: function () {
                    },
                    success: function (result) {
                        if (result.Status) {
                            var $Total = 0;
                            $.each(result.Data, function (index, item) {
                                $Total += parseFloat(item.LoanMatchAmount);
                                $("#MatchCreditTemplete").tmpl(item).insertBefore($("#rowMatchAmountTotal"));
                            });
                            $("#totalMatchAmount").text($Total.toFixed(2));
                        }
                    }
                });

                $("#animation").hide();
                $("#showResult").show();
            }
            else {
                $("#animation").text(data.Message);
            }
        }
    });
});
